package com.example.task1.ui.AllService.pet;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.bean.PetAskListBean;
import com.example.task1.ui.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

public class PetAskListAdapter extends BaseAdapter<PetAskListBean.RowsDTO> {

    private Context context;
    private List<PetAskListBean.RowsDTO> data = new ArrayList<>();
    private TextView userContext;
    private TextView tvName;
    private TextView tvJobName;
    private TextView tvYear;
    private TextView tvGoodAt;
    private ImageView image;

    public PetAskListAdapter(Context context) {
        this.context = context;
    }

    public void setData(List<PetAskListBean.RowsDTO> rows) {
        int size = data.size();
        data.addAll(rows);
        notifyItemInserted(size);
    }

    @Override
    protected int getLayout() {
        return R.layout.petasklayout;
    }

    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected List<PetAskListBean.RowsDTO> getData() {
        return data;
    }

    @Override
    protected void onBind(myHolder holder, PetAskListBean.RowsDTO date) {
        userContext.setText("问诊问题：" + date.getQuestion());
        if (date.getDoctor() != null) {
            tvName.setText("姓名：" + date.getDoctor().getName());
            tvJobName.setText("医生职称：" + date.getDoctor().getJobName());
            tvYear.setText("医龄：" + date.getDoctor().getWorkingYears());
            tvGoodAt.setText("擅长方向：" + date.getDoctor().getGoodAt());
            MyApplication.glide(image,date.getDoctor().getAvatar());
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyApplication.intent(context,PetAskDetailsActivity.class,date.getId());
            }
        });
    }

    @Override
    protected void holder(View itemView) {
        initView(itemView);
    }

    private void initView(View itemView) {
        userContext = (TextView) itemView.findViewById(R.id.user_context);
        tvName = (TextView) itemView.findViewById(R.id.tv_name);
        tvJobName = (TextView) itemView.findViewById(R.id.tv_jobName);
        tvYear = (TextView) itemView.findViewById(R.id.tv_year);
        tvGoodAt = (TextView) itemView.findViewById(R.id.tv_goodAt);
        image = (ImageView) itemView.findViewById(R.id.image);
    }
}
